package src.main.danli;

import java.io.Serializable;

/**序列化内部类单例*/
public class SerializedSingle implements Serializable {
    private static final long serialVersionUID=-1L;
    private SerializedSingle(){}
    private static class Single{
       private static final SerializedSingle serializedSingle=new SerializedSingle();
    }
    public static SerializedSingle getInstance(){
        return Single.serializedSingle;
    }

    //这样当JVM从内存中反序列化地"组装"一个新对象时就会自动调用这个readResolve方法来返回我们指定好的对象了,否则会被破坏单例。
    protected Object readResolve() {
        return getInstance();
    }
}
